<?php
class Default_Model_Customer {
	protected $_table = null;
	public function __construct() {
		$this->_table = new Default_Model_DbTable_Customer ();
	}
	public function getAll() {
		$select = $this->_table->select ();
		return $this->_table->fetchAll ( $select )->toArray ();
	}
	public function getByCondition($condition = array(), $type = '*', $orderby = array('order_id'), $pageSize = 0, $page = 1) {
		$select = $this->_table->getAdapter ()->select ();
		$table = $this->_table->info ( 'name' );
		$select->from ( $table, $type );
		$select->where ( "1 =?", 1 );
		// print_r($condition);
		
		if (isset ( $condition ["customer_id"] ) && $condition ["customer_id"] != '') {
			$select->where ( " customer_id = ?", $condition ["customer_id"] );
		}
		
		if ('count(*)' == $type) {
			return $this->_table->getAdapter ()->fetchOne ( $select );
		} else {
			$select->order ( $orderby );
			if ($pageSize > 0 and $page > 0) {
				$start = ($page - 1) * $pageSize;
				$select->limit ( $pageSize, $start );
			}
			$sql = $select->__toString ();
			$result = $this->_table->getAdapter ()->fetchAll ( $sql );
			
			return $result;
		}
	}
}